
/**
 * @file simple_test.c
 *
 */



/*********************
 *      INCLUDES
 *********************/
#include "albumpageui.h"
#include	"lv_100ask_file_explorer.h"
#include	"simple_test.h"

//#if LV_100ASK_FILE_EXPLORER_SIMPLE_TEST != 0

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/



/**********************
 *  STATIC PROTOTYPES
 **********************/
static void file_explorer_simple_test_event_handler(lv_event_t * e);
lv_obj_t * file_explorer;
extern  lv_obj_t * ui_Image1;
/**********************
 *  STATIC VARIABLES
 **********************/


/**********************
 *      MACROS
 **********************/


/**********************
 *   GLOBAL FUNCTIONS
 **********************/

void lv_100ask_file_explorer_simple_test(void)
{
    file_explorer = lv_100ask_file_explorer_create(lv_scr_act());

#if LV_USE_FS_WIN32 || LV_USE_FS_FATFS
    //����̷���Ҫ������ lv_conf.h �е� LV_FS_WIN32_LETTER
    // [windows]��ĳ�����̵ĸ�Ŀ¼
    lv_100ask_file_explorer_open_dir(file_explorer, "D:");
    //lv_100ask_file_explorer_open_dir(file_explorer, "D:/100ask");
    //lv_100ask_file_explorer_open_dir(file_explorer, "D:/100ask/tmp");

#if LV_100ASK_FILE_EXPLORER_QUICK_ACCESS
    // [windows]���ÿ��ٷ���·��������̷���Ҫ������ lv_conf.h �е� LV_FS_WIN32_LETTER
    // ��������windowsϵͳ��Ȩ�����⣬���ǲ��ܷ���ϵͳ�̣�����ֻ�Ǹ���ʾ����ģ��windows��Դ�������еĿ��ٷ�����
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_HOME_DIR, "C:/Users/Public/Desktop");
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_VIDEO_DIR, "C:/Users/Public/Videos");
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_PICTURES_DIR, "C:/Users/Public/Pictures");
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_MUSIC_DIR, "C:/Users/Public/Music");
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_DOCS_DIR, "C:/Users/Public/Documents");
#endif

#else
    // [linux]�򿪸�Ŀ¼
    lv_100ask_file_explorer_open_dir(file_explorer, "/");

#if LV_100ASK_FILE_EXPLORER_QUICK_ACCESS
    // [linux]���ÿ��ٷ���·��
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_HOME_DIR, "/root");
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_VIDEO_DIR, "/root/Videos");
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_PICTURES_DIR, "/root/Pictures");
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_MUSIC_DIR, "/root/Music");
    lv_100ask_file_explorer_set_quick_access_path(file_explorer, LV_100ASK_EXPLORER_DOCS_DIR, "/root/Documents");
#endif

#endif

    lv_obj_add_event_cb(file_explorer, file_explorer_simple_test_event_handler, LV_EVENT_VALUE_CHANGED, NULL);

}


/*=====================
 * Other functions
 *====================*/

/**********************
 *   STATIC FUNCTIONS     LV_OBJ_FLAG_USER_1
 **********************/

extern      lv_obj_t * ui_albumpage;
static void file_explorer_simple_test_event_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * obj = lv_event_get_target(e);


    //uint16_t col;    uint16_t row;    lv_table_get_selected_cell(obj, &row, &col);// LV_LOG_USER("row:%d,col:%d", row,col);
    //  这里是文件名才传回来，文件夹没有传回
    if(code == LV_EVENT_VALUE_CHANGED) {
        char * cur_path =  lv_100ask_file_explorer_get_cur_path(obj);
        //char * sel_fn = lv_100ask_file_explorer_get_sel_fn(obj);
        char * sel_fn = lv_100ask_file_explorer_get_sel_fn(obj);
        LV_LOG_USER("%s: cur_path=%s,fn=%s", __FUNCTION__,cur_path, sel_fn);


        if((strcmp((sel_fn + (strlen(sel_fn) - 4)) , ".jpg") == 0) || (strcmp((sel_fn + (strlen(sel_fn) - 4)) , ".JPG") == 0)){
            sprintf(g_fullPath,"%s/%s",g_curPath,sel_fn);
            printf("fullPath:%s,total:%d",g_fullPath,imgs_total_nums);
            g_curImg_p = findImgListByName(sel_fn);
            lv_img_set_src(ui_Image1, g_fullPath);

        lv_obj_add_flag(file_explorer, LV_OBJ_FLAG_HIDDEN); //  隐藏文件浏览界面

        lv_obj_clear_flag(ui_albumpage, LV_OBJ_FLAG_HIDDEN);//  显示图片界面，更新图片
        }

    }
}

//#endif  /*SIMPLE_TEST*/
